﻿using Anke.SHManage.BLL;
using Anke.SHManage.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Anke.SHManage.Web.Areas.DD.Controllers
{
    public class TelBookController : Controller
    {
        private static object m_SyncRoot = new Object();//互斥对象
        //
        // GET: /DD/TelBook/

        public ActionResult TelBookList()
        {
            return View();
        }

        //查询电话本
        public ActionResult DataLoad()
        {
            //获取页容量
            int pageSize = int.Parse(Request.Form["rows"]);
            //获取请求的页码
            int pageIndex = int.Parse(Request.Form["page"]);
            //获取查询条件           
            string phoneType = Request.Form["phoneType"];
            string name = Request.Form["name"];
            string phone = Request.Form["phone"];

            E_StatisticsPermisson em = UserOperateContext.Current.getMaxPerForStatistics();
            string selfWorkCode = UserOperateContext.Current.Session_UsrInfo.WorkCode;
            string selfCenterID = UserOperateContext.Current.Session_UsrInfo.P_Department.DispatchSubCenterID;
            string selfStationID = UserOperateContext.Current.Session_UsrInfo.P_Department.DispatchSationID;
            string eventDispatchCenterID = UserOperateContext.Current.Seesion_Dispatch_SubCenterID; //2020-11-23 hsp 登录人所处急救中心
            TelBookBLL bll = new TelBookBLL();
            var list = bll.GetTelBookList(pageSize, pageIndex, phoneType, name, phone,
                                          em, selfWorkCode, selfCenterID, selfStationID, eventDispatchCenterID);
            JsonResult j = this.Json(list, "appliction/json", JsonRequestBehavior.AllowGet);
            return j;

        }


        // 获取电话类型     
        [HttpPost]
        public ActionResult GetPhoneType()
        {
            try
            {
                TelBookBLL bll = new TelBookBLL();
                var result = new object();
                //增加缓存
                lock (m_SyncRoot)
                {
                    result = CacheHelper.GetCache("GetPhoneType");
                    if (result == null)
                    {
                        string eventDispatchCenterID = UserOperateContext.Current.Seesion_Dispatch_SubCenterID; //2021-06-04 gdg 登录人所处急救中心
                        result = bll.GetPhoneTypeList(eventDispatchCenterID);
                        CacheHelper.SetCache("GetPhoneType", result);
                    }
                }
                return Json(result);
            }
            catch (Exception)
            {
                return this.Json("");
            }
        }

    }
}
